package logic

import (
	"context"
	"encoding/json"

	"blogcenter/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PingLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
	return &PingLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PingLogic) Ping() (resp string, err error) {
	// 创建返回的 JSON 结构
	response := struct {
		Message string `json:"message"`
	}{
		Message: "blogcenter pong",
	}

	// 将结构体序列化为 JSON 字符串
	jsonResp, err := json.Marshal(response)
	if err != nil {
		l.Logger.Errorf("JSON marshal error: %v", err)
		return "", err
	}

	return string(jsonResp), nil
}
